import QtQuick 1.1
import com.nokia.meego 1.0
import RecentModel 1.0

PageTemplate {
    id: recentPage

    CaptionItem {
        id: captionItem
        Row {
            id: fileRow
            parent: captionItem.captionContentRow
            width: captionItem.captionContentRow.width
            TextField {
                id: fileNameEdit
                width: fileRow.width - openButton.width
            }
            Button {
                id: openButton
                text: qsTr("Open")
                onClicked: {
                    var f = fileNameEdit.text;
                    if (appWindow.editor.loadDocument(f))
                        appWindow.showEditorPage();
                }
                Component.onCompleted: {
                    // set the minimum button width to still have the text on it fully visible
                    var button = Qt.createQmlObject('import QtQuick 1.1; import com.nokia.meego 1.0; Button { text:"" }', fileRow);
                    var code = 'import QtQuick 1.1; Text { font.pixelSize:' + button.font.pixelSize + '; font.bold:' + button.font.bold;
                    if (button.font.weight == Font.Light) code += ';font.weight:"Light"'
                    else if (button.font.weight == Font.Normal) code += ';font.weight:"Normal"'
                    else if (button.font.weight == Font.DemiBold) code += ';font.weight:"DemiBold"'
                    else if (button.font.weight == Font.Bold) code += ';font.weight:"Bold"'
                    else if (button.font.weight == Font.Black) code += ';font.weight:"Black"'
                    var text = Qt.createQmlObject(code + '; text:"' + qsTr("Create") + '"}', fileRow, "calcTextWidth");
                    var spacing = 10;
                    width = text.width + spacing*2;
                    button.destroy();
                    text.destroy();
                }
            }
        }
    }

    RecentModelItem {
        id: recentModelItem
    }

    InfoItemView {
        id: recentListView
        y: captionItem.height
        width: recentPage.width
        height: recentPage.height - captionItem.height
        model: recentModelItem
        delegate: InfoItemDelegate {
            id: listItem
            arrowEnabled: false
            Column {
                id: listItemContent
                Label {
                    text: fileName
                    font.weight: Font.Bold
                    font.pointSize: 16
                    width: listItem.width
                    elide: Text.ElideRight
                }
                Label {
                    text: filePath
                    font.weight: Font.Light
                    font.pointSize: 16
                    width: listItem.width
                    elide: Text.ElideLeft
                }
            }
            onItemClicked: {
                fileNameEdit.text = filePath
            }
        }
    }
}
